package pers.mor.tomcat.catalina;

import cn.hutool.log.LogFactory;

import java.util.HashMap;
import java.util.Map;

public class Engine {

    private String name;
    private String defaultHost;
    private Map<String, Host> hostMap;

    public Engine(String name, String defaultHost) {
        this.name = name;
        this.defaultHost = defaultHost;
        this.check();
        this.hostMap = new HashMap<>();
    }

    private void check() {
        if (this.defaultHost == null || this.defaultHost.trim().equals("")) {
            this.defaultHost = "localhost";
            LogFactory.get().warn("启用 Engine 默认配置 defaultHost = {} ", this.defaultHost);
            LogFactory.get().error("发现 Engine 配置错误: /conf/server.xml 中 <Engine> 至少要配置 defaultHost 属性");
        }
    }

    public String getName() {
        return name;
    }

    public String getDefaultHost() {
        return defaultHost;
    }

    public Map<String, Host> getHostMap() {
        return hostMap;
    }

}
